import { getUserList, getUser, getUserTree, delUser, saveUser, updateUser } from '@/api/sys/user'

const actions = {
  // 获取用户列表
  getUserList({ commit }, param) {
    return new Promise((resolve, reject) => {
      getUserList(param).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  getUser({ commit }, id) {
    return new Promise((resolve, reject) => {
      getUser(id).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  updateUser({ commit }, param) {
    return new Promise((resolve, reject) => {
      updateUser(param).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  /**
   * 保存用户
   * @param {用户} data
   */
  saveUser({ commit }, param) {
    return new Promise((resolve, reject) => {
      saveUser(param).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  /**
   *  删除用户
   * @param {id} id
   */
  delUser({ commit }, id) {
    return new Promise((resolve, reject) => {
      delUser(id).then(res => {
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  }

}

export default {
  namespaced: true,
  actions
}
